/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imenu.entity;

import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Yunzi
 */
@Entity
@Table(name = "imenu_order")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ImenuOrder.findAll", query = "SELECT i FROM ImenuOrder i"),
    @NamedQuery(name = "ImenuOrder.findById", query = "SELECT i FROM ImenuOrder i WHERE i.id = :id"),
    @NamedQuery(name = "ImenuOrder.findByAmount", query = "SELECT i FROM ImenuOrder i WHERE i.amount = :amount"),
    @NamedQuery(name = "ImenuOrder.findByStoreId", query = "SELECT i FROM ImenuOrder i WHERE i.storeId = :storeId"),
    @NamedQuery(name = "ImenuOrder.findByCustomerId", query = "SELECT i FROM ImenuOrder i WHERE i.customerId = :customerId"),
    @NamedQuery(name = "ImenuOrder.findByCreateTime", query = "SELECT i FROM ImenuOrder i WHERE i.createTime = :createTime")})
public class ImenuOrder implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", insertable = false)
    private Integer id;
    @Column(name = "amount")
    private Integer amount;
    @Column(name = "store_id")
    private Integer storeId;
    @Column(name = "status")
    private Integer status;
    @Size(max = 255)
    @Column(name = "customer_id")
    private String customerId;
    @Column(name = "create_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    @Transient
    private String ymd;
    @Transient
    private String statusDesc;
    @Transient
    private String storeName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "orderId")
    private Collection<ImenuOrderItem> orderItemsCollection;

    public ImenuOrder() {
    }

    public ImenuOrder(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Integer getStoreId() {
        return storeId;
    }

    public void setStoreId(Integer storeId) {
        this.storeId = storeId;
    }

    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getStatus() {
        return status;
    }

    public String getStatusDesc() {
        switch (this.status) {
            case 1 : {
                return OrderStatus.NEW.getDesc();
            }
            case 2 : {
                return OrderStatus.ACCEPTED.getDesc();
            }
            default:
            return OrderStatus.DONE.getDesc();
        }
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public Collection<ImenuOrderItem> getOrderItemsCollection() {
        return orderItemsCollection;
    }

    public void setOrderItemsCollection(Collection<ImenuOrderItem> orderItemsCollection) {
        this.orderItemsCollection = orderItemsCollection;
    }

    public String getYmd() {
        return new java.text.SimpleDateFormat("yyyy-MM-dd").format(createTime);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ImenuOrder)) {
            return false;
        }
        ImenuOrder other = (ImenuOrder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.imenu.entity.ImenuOrder[ id=" + id + " ]";
    }
}
